#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
using namespace std;

 class Solution1 {
 public:
     string reverseWords(string s) {
         int i = 0;
         int pos = s.find(' ');
         while(pos != string::npos)
         {
             reverse(s.begin() + i, s.begin() + pos);
             i = pos + 1;
             pos = s.find(' ', i);
         }
         reverse(s.begin() + i, s.end());

         return s;
     }
 };

class Solution2 {
public:
    string reverseWords(string s) {
        int pos = 0;
        for (int i = 0; i < s.size(); i++)
        {
            if (s[i] == ' ')
            {
                reverse(s.begin() + pos, s.begin() + i);
                pos = i + 1;
            }
        }
        reverse(s.begin() + pos, s.end());

        return s;
    }
};